<template>
  <div class="page-table">
<!--    <div class="page-filter">-->
<!--      <div class="op">-->
<!--        <el-button size="mini" type="primary" plain :disabled="orderSelectedRows.length == 0" @click="openExceptionAdder('c')">处理</el-button>-->
<!--        <el-button size="mini" type="primary" plain :disabled="orderSelectedRows.length == 0" @click="relieve">解除</el-button>-->
<!--      </div>-->
<!--    </div>-->
    <ad-table ref="order" class="multi-select"
              :data="orderList" :show-summary="orderSummary" v-loading="orderInitLoading" border u-table :data-changes-scroll-top="orderIsScrollTop"
              @row-click="orderSelectRow" @selection-change="orderSelectRows"
              :searchQuery="orderSearchQuery" @search="orderGetInitList"
              @sort-change="orderSortInitList" @filter-change="orderFilterInitList"
              @table-body-scroll="orderGetMoreList" :height="tableHeight">
      <!--      v-el-table-infinite-scroll="orderGetMoreList" :infinite-scroll-distance="600"-->
      <!--      :infinite-scroll-disabled="orderComplete"-->
<!--      <ad-table-column type="selection" ctype="selection" fixed/>-->
      <ad-table-column label="序号" type="index" ctype="index" fixed/>
      <ad-table-column label="订单编号" prop="orderSubNo" ctype="orderNo" searchable w="4c1f" href="/order/detail" id="orderId"/>
      <ad-table-column label="订单状态" prop="orderStatus" dictName="order_status" filterable w="4c1f"/>
      <ad-table-column label="异常类型" prop="type" dictName="exception_type" filterable w="4c1f"/>
      <ad-table-column label="制单人" prop="orderCreateUserName" searchable w="4c1f"/>
      <ad-table-column label="责任人" prop="chargeUserName" searchable w="4c1f"/>
      <ad-table-column label="超时时间" prop="overTimeStr" sortable w="1f"/>
      <ad-table-column label="出发地" prop="startCode" searchable queryPro="startName" ctype="city"/>
      <ad-table-column label="目的地" prop="destinationCode" searchable queryPro="destinationName" ctype="city"/>
      <ad-table-column label="车辆名称" prop="carName" searchable w="4c1f"/>
      <ad-table-column label="车架号" prop="vin" ctype="vin-2f" searchable w="4c1f"/>
<!--      <ad-table-column label="是否处罚" prop="punish">-->
<!--        <template slot-scope="{row}">-->
<!--          <el-popconfirm title="超时是否处罚？" confirm-button-text="是" cancel-button-text="否" confirm-button-type="text" @onConfirm="yes(row)" @onCancel="no(row)">-->
<!--            <el-button class="op-btn" slot="reference" type="text">{{row.punish ? '是' : '否'}}</el-button>-->
<!--          </el-popconfirm>-->
<!--        </template>-->
<!--      </ad-table-column>-->
      <ad-table-column width="auto"/>
    </ad-table>

    <el-dialog title="订单" :visible.sync="dialog.show" custom-class="ad-dialog" width="1000px">
<!--      <exception-adder :mode="dialog.mode" :id="orderSelectedRowId" :visible.sync="orderAdder.visible"/>-->
      <exception-adder v-loading="dialog.loading" :show.sync="dialog.show" :mode="dialog.mode" :query="dialog.query" @loading="dialog.loading = $event" @refresh="orderGetInitList" />
    </el-dialog>
  </div>
</template>

<script>
import AdDatetimeRange from '@/components/AdDateTimeRange'
import AdTable from '@/components/AdTable'
import AdTableColumn from '@/components/AdTable/AdTableColumn'
import exceptionAdder from './dialog/exceptionAdder'
import adTable from '@/mixins/adTable/index'
import { getWaitList as orderApiGetList, punish, relieve } from '@/api/order/exception'

export default {
  components: { AdDatetimeRange, AdTable, AdTableColumn, exceptionAdder },
  dicts: ['order_status','exception_type'],
  mixins: [adTable([{name: 'order'}])],
  data() {
    return {
      searchQuery: {},
      tableHeight: document.documentElement.clientHeight - 134,
      dialog: {
        title: '',
        content: '',
        show: false,
        loading: false,
        mode: '',
        query: {}
      }
    }
  },
  created() {
    this.orderGetInitList()
  },
  methods: { orderApiGetList,
    yes(row) {
      if (!row.punish) {
        punish(row.id).then(res => this.orderGetInitList())
      }
    },
    no(row) {
      if (row.punish) {
        punish(row.id).then(res => this.orderGetInitList())
      }
    },
    relieve() {
      this.$confirm(`是否解除?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        relieve(this.crud.selections[0].id).then(res => this.crud.refresh())
      }).catch(() => {})
    },
    openExceptionAdder(mode) {
      const show = true
      switch (mode) {
        case 'c':
          this.dialog = { show, mode, title: '异常操作处理', query: { id: this.orderSelectedRowId, detail: this.orderSelectedRow } }; break
        // case 'r':
        //   this.dialog = { show, mode, title: '修改客户', content: 'finishCustomerAdder', loading: true, query: { id: this.selectedCustomerId } }; break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.op-btn { padding: 0; font-size: 12px; font-weight: normal; }
</style>